// pages/goods_list/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabs: [
      {
        id: 0,
        title: '综合',
        isActive: true
      },
      {
        id: 1,
        title: '销量',
        isActive: false
      },
      {
        id: 2,
        title: '价格',
        isActive: false
      }
    ],
    goodsList: []
  },
  QueryParams: {
    query: '',
    cid: '',
    pagenum: 1,
    pagesize: 10
  },
  goodsdetail:function(e){
    wx.navigateTo({
      url: `/pages/goods_detail/index?id=` +e.currentTarget.id,
    })
  },
  onLoad: function (options) {
    // console.log(options)
    var {id}=options;
    console.log(id)
    wx.request({
      url: 'http://122.112.245.197:5000/api/top250',
      success:(res=>{
        var goodslist=[];
        res.data.forEach(item=>{
          if(item.sort==id){
          goodslist.push(item)}
        })
        this.setData({
          goodsList:goodslist,
        })
        //console.log(res);
          
        this.QueryParams.cid = options.cid || '';
        this.QueryParams.query = options.query || '';
        // this.getGoodsList();
      })
    })
  },
  /**
   * 子向父转递数据
   */
  handleItemChange(e) {
    const { index } = e.detail;
    let { tabs } = this.data;
    tabs.forEach((item, i) => item.isActive = index === i ? true : false);
    this.setData({
      tabs
    })
  },


})